package com.woniuxy.dao;

import com.woniuxy.entity.Permission;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PermissionMapper {
    /**
     * 通过用户id查询某个用户所有的权限
     */
    @Select("SELECT DISTINCT p.* FROM permission p INNER JOIN role_permission rp ON p.id = rp.permission_id INNER JOIN role_user ru ON ru.role_id=rp.role_id WHERE ru.user_id=#{userId}")
    List<Permission> findPermissionsByUserId(Integer userId);

    /**
     * 查询所有的权限
     */
    @Select("SELECT * FROM permission")
    List<Permission> findAll();
    /**
     * 查询某个角色有哪些权限
     */
    @Select("SELECT DISTINCT permission_id FROM role_permission WHERE role_id =#{roleId}")
    List<Integer> findPermissionIds(Integer roleId);
}
